"use strict";
//4.代理模式典型应用之缓存代理
var count = 0;
function factorial(num) {
    count++;
    if (num <= 1)
        return 1;
    return num * factorial(num - 1);
}
;
console.log('factorial1:', factorial(3), 'count:', count);
console.log('factorial1:', factorial(6), 'count:', count);
//代理缓存
function proxy(fn) {
    var cache = {};
    return function (num) {
        if (num in cache) {
            return cache[num];
        }
        else {
            return cache[num] = fn(num);
        }
    };
}
var fn2 = proxy(factorial);
// console.log('factorial2:', fn2(3), 'count:', count);
// console.log('factorial2:',fn2(6),'count:',count);
